﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Daco.Web.Store;

namespace Daco.Web.Controls
{
    public partial class NewestProductList : Daco.Web.UI.BaseUserControl
    {
        public int ItemCount { get; set; }

        public NewestProductList()
        {
            this.ItemCount = 3;
            this.Load += new EventHandler(NewestProductList_Load);
        }

        void NewestProductList_Load(object sender, EventArgs e)
        {
            rpNewestProduct.DataSource = CProduct.GetNewestProducts(this.ItemCount);
            rpNewestProduct.DataBind();
        }

        protected string GetPriceDetail(object item)
        {
            CProduct current = (CProduct)item;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (!current.EnablePriceConfidential && current.UnitPrice > 0)
            {
                sb.Append(@"<b>Giá: </b><label style=""color: Red;"">");
                sb.Append(current.UnitPrice.ToString(Config.CSiteConfig.Current.DoubleFormatString));
                sb.Append(current.Currency);
                sb.Append("</label>");
            }

            return sb.ToString();
        }

        protected string GetPhotoUrl(object item)
        {
            Daco.Web.Store.CProduct p = (Daco.Web.Store.CProduct)item;
            return Page.ResolveUrl(string.Format("~/Handlers/PHOTOHandler.ashx?pid={0}", p.GetDefaulPhoto().PhotoID));
        }
    }
}